package com.eianiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.eianiao.bean.SetmealDish;
import com.eianiao.dao.SetmealDishDao;
import com.eianiao.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author eianiao
 * @Date 2022 06
 * @Version 1.0
 **/
@Service
@Transactional
public class SetmealDishServiceImpl implements SetmealDishService {


    @Autowired
    private SetmealDishDao setmealDishDao;

    /**
     * 添加套餐中的菜品
     *
     * @param setmealDish
     * @return
     */
    @Override
    public int add(SetmealDish setmealDish) {

        return setmealDishDao.insert(setmealDish);
    }


    /**
     * 根据deleteBySetmealId删除套餐
     *
     * @param categoryId
     * @return
     */
    @Override
    public int deleteBySetmealId(Long categoryId) {
        LambdaQueryWrapper<SetmealDish> qw = new LambdaQueryWrapper<>();
        qw.eq(SetmealDish::getSetmealId,categoryId);
        System.out.println("*******************************************");
        return setmealDishDao.delete(qw);
    }

    /**
     * 根据dish_id删除套餐的菜品
     *
     * @param id
     * @return
     */
    @Override
    public int deleteByDishId(Long id) {
        LambdaQueryWrapper<SetmealDish> qw = new LambdaQueryWrapper<>();
        qw.eq(SetmealDish::getDishId,id);
        return setmealDishDao.delete(qw);
    }

    /**
     * 查询套餐中的菜品回显
     *
     * @param categoryId
     * @return
     */
    @Override
    public List<SetmealDish> findBySetmealId(Long categoryId) {
        LambdaQueryWrapper<SetmealDish> qw = new LambdaQueryWrapper<>();
        qw.eq(SetmealDish::getSetmealId,categoryId);

        return setmealDishDao.selectList(qw);
    }


}
